﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.produceLinq;
using dhDataAcess.dataAcess.produceDataSetTableAdapters;
using dhDataAcess.dataAcess;
using dhDataAcess.Model;
using dhDataAcess.baseBLL;
using dhDataAcess.produceDAL;
using dhDataAcess.dataAcess.ViewDataSetTableAdapters;
using dhDataAcess.sysDAL;



namespace dhSystemBLL.produceBLL
{
   public  class pdpqbBLL
    {
       
       private V_piaoranpaiqiTableAdapter _V_piaoranpaiqiAdapter = null;
       private V_piaoranpaiqiTableAdapter V_piaoranpaiqiAdapter
        {
            get
            {
                if (_V_piaoranpaiqiAdapter == null) _V_piaoranpaiqiAdapter = new V_piaoranpaiqiTableAdapter();
                return _V_piaoranpaiqiAdapter;
            }
        }
       private pdpqbTableAdapter _pdpqbAdapter = null;
       private pdpqbTableAdapter pdpqbAdapter
        {
            get
            {
                if (_pdpqbAdapter == null) _pdpqbAdapter = new pdpqbTableAdapter();
                return _pdpqbAdapter;
            }
        }
        /// <summary>
        /// 查询胚带排期表
        /// </summary>
        /// <returns></returns>

       public produceDataSet.pdpqbDataTable getpdpqbAll()
        {
            try
            {
                return pdpqbAdapter.GetDatapdpqbALL();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
       /// <summary>
       /// 查询视图胚带排期表根据订单明细状态
       /// </summary>
       /// <returns></returns>

       public ViewDataSet.V_piaoranpaiqiDataTable getV_piaoranpaiqiAllBybillStatus(string billStatus)
       {
           try
           {
               return V_piaoranpaiqiAdapter.GetDataV_piaoranpaiqiBybillStatus(billStatus);
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }
       /// <summary>
       /// 查询视图胚带排期表根据排期号
       /// </summary>
       /// <returns></returns>

       public ViewDataSet.V_piaoranpaiqiDataTable getV_piaoranpaiqiAllBybilloNo(string billoNo)
       {
           try
           {
               return V_piaoranpaiqiAdapter.GetDataV_piaoranpaiqiBybillonNo (billoNo);
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }
       /// <summary>
       /// 查询视图胚带排期表根据排期号
       /// </summary>
       /// <returns></returns>

       public ViewDataSet.V_piaoranpaiqiDataTable getV_piaoranpaiqiAllBycustName(string custName)
       {
           try
           {
               return V_piaoranpaiqiAdapter.GetDataV_piaoranpaiqiBycustName(custName);
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }
       /// <summary>
       /// 查询视图胚带排期表根据排期号
       /// </summary>
       /// <returns></returns>

       public ViewDataSet.V_piaoranpaiqiDataTable getV_piaoranpaiqiAllByorderDetailNo(string orderDetailNo)
       {
           try
           {
               return V_piaoranpaiqiAdapter.GetDataV_piaoranpaiqiByorderDetailNo (orderDetailNo);
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }
        /// <summary>
        /// 根据编号查询信息表
        /// </summary>
        /// <param name="cname"></param>
        /// <returns></returns>

       public produceDataSet.pdpqbDataTable getpdpqbBybilloNo(string billoNo)
        {
            try
            {

                return pdpqbAdapter.GetDatapdpqbBybilloNo(billoNo);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }

       public produceDataSet.pdpqbDataTable getpdpqbBybillStatus(string billStatus)
       {
           try
           {

               return pdpqbAdapter.GetDatapdpqbBybillStatus (billStatus);

           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }


        /// <summary>
        /// 插入信息
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

       public int pdpqbInsert(pdpqbModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pdpqbDAL pdpqb = new pdpqbDAL(tn, conn);
                basListDAL basList = new basListDAL(tn, conn);
                pdpqb.pdpqbInsert (row);
                //更新订单序列号
                string orderSerial = basicSql.getOrderSerail("排期号");
                basList.basListretbasNumUpdate((Convert.ToInt32(orderSerial) + 1).ToString(), "排期号");

                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

       public int pdpqbUpdate(pdpqbModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pdpqbDAL pdpqb = new pdpqbDAL(tn, conn);
                pdpqb.pdpqbUpdate(row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="cname"></param>
        /// <returns></returns>

       public int pdpqbDel(string billoNo)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pdpqbDAL pdpqb = new pdpqbDAL(tn, conn);
                pdpqb.pdpqbDel(billoNo);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
 
    }
}
